#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=5e3+5;
typedef short LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL dp[maxn][maxn];
char a[maxn];
int main(void){
   cin.tie(0);std::ios::sync_with_stdio(false);
   int n;cin>>n;
   cin>>(a+1);
   memset(dp,0x3f,sizeof(dp));
   for(int i=1;i<=n;i++){
       dp[i][i]=0;
       if(i!=n) dp[i][i+1]=dp[i][i]+(a[i]!=a[i+1]);
   }
   for(int len=3;len<=n;len++){
       for(int i=1;i+len-1<=n;i++){
           int l=i;int r=i+len-1;
           if(a[l]==a[r]){
              dp[l][r]=min(dp[l][r],dp[l+1][r-1]);
           }
           else{
              dp[l][r]=min(dp[l][r],(short)min(1+dp[l+1][r],1+dp[l][r-1]));
           }
       }
   }
   cout<<dp[1][n]<<"\n";
   return 0;
}
